package com.itheima.tlias.controller;

import com.itheima.tlias.model.dos.EmpAndExprDo;
import com.itheima.tlias.model.dos.EmpDO;
import com.itheima.tlias.model.dto.EmpAddDTO;
import com.itheima.tlias.model.dto.EmpQueryDTO;
import com.itheima.tlias.model.entity.Emp;
import com.itheima.tlias.model.response.EmpExprResult;
import com.itheima.tlias.model.response.PageResult;
import com.itheima.tlias.model.response.Result;
import com.itheima.tlias.service.EmpService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping(path = "/emps")
public class EmpController {

    final EmpService empService;
    public EmpController(EmpService empService) {
        this.empService = empService;
    }


    @GetMapping
    public Result<PageResult<EmpDO>> empListPageQuery(EmpQueryDTO dto){
        PageResult<EmpDO> dta = empService.empListPageQuery(dto);
        return Result.success(dta);
    }
    @PostMapping
    public Result add(@RequestBody EmpAddDTO dto){
        empService.add(dto);
        return Result.success();
    }
    @PutMapping
    public Result updata(@RequestBody EmpAddDTO dto){
        empService.updata(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<EmpAndExprDo> selectById(@PathVariable Integer id){
        EmpAndExprDo emp = empService.selectById(id);
        return  Result.success(emp);

    }
    @DeleteMapping()
    public Result deleteEmp(@RequestParam List<Integer> ids){
        empService.deleteEmp(ids);
        return Result.success();

    }
    @GetMapping("/list")
    public Result<List<Emp>> emplist(){
        List<Emp> emp = empService.emplist();
       return Result.success(emp);
    }
}
